<template>
  <div class="wrapper wrapper-content animated fadeInRight v-cloak" v-cloak>
    <div class="row">
      <div class="col-md-12">
        <div class="table-responsive table-scrollable">
          <table class="table table-bordered table-striped  table-hover">
            <thead>
            <tr>
              <th style="width:20px;">#</th>
              <th>用户姓名</th>
              <th>用户账号</th>
              <th>所属机构</th>
              <th>使用状态</th>
            </tr>
            </thead>
            <tbody>
            <tr v-if="result.data.data && result.data.data.length>0" v-for="(item, index) in result.data.data">
              <td>{{(result.data.pageIndex-1)*result.data.pageSize + index+1}}</td>
              <td>{{item.name}}</td>
              <td>{{item.account}}</td>
              <td>{{item.orgName}}</td>
              <td>{{stateEnum(item.state)}}</td>
            </tr>
            <tr v-if="result.data.data==null || result.data.data.length==0">
              <td colspan="5">
                <div class="alert"><strong>{{ result | message }}</strong></div>
              </td>
            </tr>
            </tbody>
          </table>
        </div>
        <div class="b_page" v-html="tagPages"></div>
      </div>
    </div>
  </div>
</template>
<script type="text/javascript">
  import '@/assets/css/style.css'
  import axios from 'axios'
  import {$storage, apiUtil, axiosContentType, site} from '@/assets/js/boss'
  import '@/assets/js/pageTag'

  export default {
    data() {
      return {
        result: {data: {pageIndex: 1, data: []}, message: ''},
        tagPages: ''
      }
    },
    mounted() {
      let that = window.$vueApp = this;
      document.getElementsByTagName('body')[0].className = 'fixed-sidebar full-height-layout';
      this.staff.init(function () {
        if (apiUtil.existSessionKey(site.authRole.info)) {
          that.page();
        }
      });
    },
    methods: {
      page(pageIndex) {
        let that = this;
        if (!pageIndex) pageIndex = 1;
        axios.post(site.staff.getUserByRole + $storage.getItem(site.authRole.info) + '/' + pageIndex
          , {}
          , axiosContentType.xWwwFormUrlencoded
        ).then(function (response) {
          const result = response.data;
          if (result.code === 0) {
            that.result = result;
            that.tagPages = that.tag.page(result.data);
          } else {
            alert(result.message);
          }
        });
      },
      stateEnum(key) {
        let val = '未知';
        switch (key) {
          case 0:
            val = '启用';
            break;
          case 1:
            val = '禁用';
            break;
        }
        return val;
      }
    }
  }
</script>
